package com.ease.core.components {
   import com.ease.core.managers.ViewManager;
   import com.ease.core.model.ViewDefine;

   import flash.display.DisplayObject;

   import mx.collections.ArrayCollection;
   import mx.containers.HBox;
   import mx.controls.Label;
   import mx.core.*;

   public class StageWindowBar extends HBox {
      private var labelCtrl:Label = null;

      public var stageWindow:StageWindow = null;

      public function StageWindowBar() {
         super();
         this.horizontalScrollPolicy = ScrollPolicy.AUTO;
         this.styleName = "stageWindowBar";
		 this.setStyle("verticalAlign","middle");
      }

      override protected function createChildren():void {
         super.createChildren();
      }

      public function addViewWindow(viewWindow:ViewWindow, stageWindow:StageWindow, isMaximizing:Boolean = false):void {

         var dragToolBar:FastViewBar = new FastViewBar();
         dragToolBar.isMaximizing = isMaximizing;
         dragToolBar.viewWindow = viewWindow;
         dragToolBar.stageWindow = stageWindow;
         dragToolBar.height = 26;
		 dragToolBar.setStyle("verticalAlign","middle");
		 
         var toolbar:ToolBar = new ToolBar();

         var array:ArrayCollection = new ArrayCollection();
         for each (var dockingView:DockingView in viewWindow.getChildren()) {
            var viewdef:ViewDefine = ViewManager.getInstance().getViewDefine(dockingView.viewId);
            array.addItem({icon: viewdef.icon, toolTip: viewdef.label});
         }
         toolbar.dataProvider = array;
         dragToolBar.addChild(toolbar);

         this.addChild(dragToolBar);
      }

      public function clearViewWindows():void {
         doClearViewWindows();
      }

      public function clearViewWindowsForMaximization():void {
         doClearViewWindows(true);
      }

      private function doClearViewWindows(isMaximizing:Boolean = false):void {
         for (var i:int = this.numChildren - 1; i >= 0; i--) {
            var displayObject:DisplayObject = this.getChildAt(i);
            if (displayObject is FastViewBar) {
               var fastViewBar:FastViewBar = displayObject as FastViewBar;
               if (isMaximizing) {
                  if (fastViewBar.isMaximizing == true) {
                     this.removeChildAt(i);
                  }
               }
               else {
                  this.removeChildAt(i);
               }
            }
         }
      }
   }
}
